<?php defined('SYSPATH') or die();?>


    <div class="page out" id="productList">
        <div class="header_top">
            <a class="back-link-icon" href="javascript:;" data-rel="back"></a>
            <h1 class="page-title-bar">商品列表</h1>
        </div>
        <!-- 公用顶部 -->
        <div class="page-content" id="scrollDiv">
            <div class="tip-search-wrap">
                <form name="" id="search-form" class="fenxiao_product_search_fm" action="javascript:;">
                    <div class="search-bar">

                        <input type="search" name="" id="product_keyword" class="search-text" placeholder="请输入商品关键词" />
                        <i class="search-icon"></i>
                    </div>
                </form>
            </div>
            <div class="search-bg-layer"></div>
            <div class="search-filter-bar">
                <div class="search-tab-item col-2">
                    <strong class="tab-name">商品类型筛选</strong>
                    <ul class="item-list" id="p_type">
                        <!--<li>所有产品</li> -->
                        {loop $products $product}
                        <li value="{$product['id']}">{$product['modulename']}</li>
                        {/loop}
                    </ul>
                </div>
                <div class="search-tab-item col-2">
                    <strong class="tab-name">排序</strong>
                    <ul class="item-list" id="order_container">
                        <li class="on" ordertype="0">推荐产品</li>
                        <li ordertype="1">最新产品</li>
                    </ul>
                </div>
            </div>
            <div class="search-list-wrap">
                <ul class="search-product-list" id="product_list">

                </ul>
                <div class="null-order-box hide" id="product_list_none">
                    <div class="info">
                        <i class="icon"></i>
                        <p class="txt">暂无相关产品</p>
                    </div>
                </div>
                <div class="no-info-bar" id="fenxiao_product_no_more" style="display: none;">没有更多结果了！</div>
                <div class="loading-on">
                    <img src="{$GLOBALS['cfg_public_url']}images/Loading-on.gif" alt="" title="" />
                    <p>正在加载数据...</p>
                </div>
            </div>
        </div>
    </div>

  <script>
      (function(){

          var SITEURL = "{URL::site()}";
          var CURRENCY_SYMBOL="{Currency_Tool::symbol()}";
          var gbl_page=1;
          var gbl_is_loading=false;
          var gbl_last_index=0;

          $("#productList .search-tab-item .tab-name").on("click",function(){
              $(this).parent(".search-tab-item").addClass("cur-tab-item").siblings().removeClass("cur-tab-item");
              $("#productList .search-list-wrap").css("overflow","hidden");
              $("#productList .search-bg-layer").show();
          });

          $("#productList .search-tab-item .item-list>li").on("click",function(){

              var val = $(this).attr('value');
              var txt = $(this).text();
              if(val)
              {
                  $(this).parent().siblings('.tab-name').text(txt);
              }


              $(this).addClass("on").siblings().removeClass("on");
              $(this).parents(".search-tab-item").removeClass("cur-tab-item");
              $("#productList .search-list-wrap").css("overflow","auto");
              $("#productList .search-bg-layer").hide();
              gbl_page=1;
              get_products(1);
          });
          $("#productList .search-tab-item .item-list>li:first").trigger('click');

          $("#productList .search-bg-layer").on("click",function(){
              $(this).hide();
              $("#productList .search-tab-item").removeClass("cur-tab-item");
              $("#productList .search-list-wrap").css("overflow","auto");
          })

          $("#productList .search-list-wrap").scroll(function(){
              var scroll_top=$('#productList .search-list-wrap').scrollTop();
              if(scroll_top+3>=($("#productList .search-list-wrap")[0].scrollHeight - $('#productList .search-list-wrap').outerHeight()))
              {
                  if(gbl_is_loading==false)
                  {
                      get_products(gbl_page+1);
                  }
              }
          });

          $("#productList .search-list-wrap").scroll(function(){
              var scroll_top=$('#productList .search-list-wrap').scrollTop();
              if(scroll_top+3>=($("#productList .search-list-wrap")[0].scrollHeight - $('#productList .search-list-wrap').outerHeight()))
              {
                  if(gbl_is_loading==false)
                  {
                      get_products(gbl_page+1);
                  }
              }
          });


          //搜索按钮
          $("#productList .search-icon").click(function(){
              gbl_page=1;
              get_products(1);
          })

          $(".fenxiao_product_search_fm").submit(function(){
              get_products(1);
          });

        //  get_products(1);

          //获取产品列表
          function get_products(page)
          {
              gbl_is_loading=true;

              $(".loading-on").show();
              var typeid=$("#p_type li.on").attr('value');
              var keyword=$("#product_keyword").val();
              var ordertype = $("#order_container li.on").attr('ordertype');
              if(page==1)
              {
                  gbl_last_index=0;
              }

              var params={
                  typeid:typeid,
                  keyword:keyword,
                  ordertype:ordertype,
                  page:page,
                  last_index:gbl_last_index
              }
              $.ajax({
                  url:SITEURL+'fenxiao/ajax_get_products',
                  type:'POST', //GET
                  data:params,
                  dataType:'json',
                  success:function(data,textStatus,jqXHR){
                      $(".loading-on").hide();
                      gbl_is_loading=false;
                      gbl_last_index = data['last_index'];
                      if(data.status)
                      {
                          var html='';

                          for(var i in data.list)
                          {
                              var row=data.list[i];
                              var commission_str= '';//row['commission_type']==1?'佣金比例：'+row['commission']:'佣金：'+CURRENCY_SYMBOL+row['commission'];

                              html+=' <li>'+
                              '<a class="item" href="'+row['url']+'" data-ajax="false">'+
                          '<div class="pic"><img src="'+row['litpic']+'" alt="'+row['title']+'" /></div>'+
                          '<div class="info">'+
                          '<h4 class="name">'+row['title']+'</h4>'+
                          '<div class="col">'+
                         // '<span class="attr">'+commission_str+'</span>'+
                          '</div>'+
                          '<div class="col">'+
                          '<span class="pri">预估收益<em class="num">'+CURRENCY_SYMBOL+'<b>'+row['profit']+'</b></em></span>'+
                          '</div></div></a></li>';
                          }
                          if(page==1)
                          {
                              $("#product_list").children().remove();
                          }

                          if(data.list.length<10)
                          {
                              $("#fenxiao_product_no_more").show();
                          }

                          $("#product_list").append(html);

                          if($("#product_list li").length==0)
                          {
                              $("#product_list_none").show();
                              $("#fenxiao_product_no_more").hide();
                          }
                          else
                          {
                              $("#product_list_none").hide();
                          }

                          if(html!='')
                          {
                              gbl_page = page;
                          }
                      }
                  }
              })


          }

      })()



  </script>